<template>
	<view class="content poRel">
		<view class="wid100 bacFFF" style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.05);">
			<view class="wid90 mar">
				<view class="hei80 dis disAl disJuB">
					<view class="fowe800 foSi30">转派订单</view>
					<view class="dis disAl">
						<view class="borRad10 dis disAl disJuC foSi20" style="width: 110rpx;height: 50rpx;" @click="xuanClick(0)"
							:style="xuan == 0?'background-color: '+theme.main_color+';color: #fff;':'background-color: #E5E5E5;color: #010101;'">更换技师</view>
						<!-- <view class="borRad10 dis disAl disJuC foSi20 mar-left20" style="width: 110rpx;height: 50rpx;" @click="xuanClick(1)"
							:style="xuan == 1?'background-color: '+theme.main_color+';color: #fff;':'background-color: #E5E5E5;color: #010101;'">委派技师</view> -->
					</view>
				</view>
				<view v-if="xuan == 0" class="dis disAl disJuB hei80">
					<view class="wid80 mar dis disAl disJuC borRad40 hei60"style="background: #E5E5E5;">
						<view class="dis disJuC" style="width: 13%;">
							<uni-icons type="search" size="30rpx" color="#AFB6B1"></uni-icons>
						</view>
						<input class="wid85 foSi20" v-model="sousuo" @input="sousuoInput" 
							placeholder="请输入技师姓名/电话查询" placeholder-style="color: #AFB6B1;"/>
					</view>
					<view class="dis disAl disJuC wid20">
						<view class="foSi25 fowe600 mar-right10">筛选</view>
						<image src="../../static/xiala.png" style="width: 16rpx;height: 10rpx;"></image>
					</view>
				</view>
			</view>
			<view style="height: 10rpx;"></view>
		</view>
		<view v-if="xuan == 1">
			<view class="wid90 mar">
				<view class="mar-top30 fowe600 foSi25"><span style="color: #FE0000;">*</span>线下技师</view>
				<view class="mar-top20 hei60 dis disAl disJuC" style="background-color: #F6F6F6;">
					<input v-model="name" class="wid95 foSi20" placeholder-style="color: #9D9D9D;" placeholder="请输入技师姓名"/>
				</view>
				<view class="mar-top30 fowe600 foSi25"><span style="color: #FE0000;">*</span>联系电话</view>
				<view class="mar-top20 hei60 dis disAl disJuC" style="background-color: #F6F6F6;">
					<input v-model="phone" class="wid95 foSi20" type="number" 
						placeholder-style="color: #9D9D9D;" placeholder="请输入联系电话"/>
				</view>
				<view class="mar-top30 fowe600 foSi25">转派备注</view>
				<view class="mar-top20" style="background-color: #F6F6F6;padding: 15rpx 0;height: 150rpx;">
					<textarea v-model="remark" class="wid95 mar hei100 foSi20" style="line-height: 36rpx;"
						placeholder-style="color:#9D9D9D" placeholder="若订单有其他特殊情况可单独备注在此处"/>
				</view>
				<view class="dis disAl disJuB mar-top30">
					<view class="fowe600 foSi25">关联代理商</view>
					<picker class="foSi25" @change="agencyChange" :value="agencyIndex" :range="agencyList">
						<view class="dis disAl foSi20">
							<view v-if="agencyIndex" class="mar-right10">{{agencyList[agencyIndex]}}</view>
							<view v-if="!agencyIndex" class="mar-right10" style="color: #A3A3A3;">请选择代理商</view>
							<uni-icons type="right" size="25rpx" color="#A3A3A3"></uni-icons>
						</view>
					</picker>
				</view>
			</view>
			<view style="height: 124rpx;"></view>
		</view>
		<view v-if="xuan == 0" style="background-color: #F3F1F1;">
			<scroll-view style="height: calc(100vh - 170rpx);" class="wid100" scroll-y="true" @scrolltolower="lower">
				<view style="height: 1rpx;"></view>
				<view v-if="list.length == 0" class="wid90 mar fowe800 foSi35">
					<view style="height: 50rpx;"></view>
					<view class="dis disJuC">
						<image src="../../static/zanwu2.png" style="width: 400rpx;height: 300rpx;"></image>
					</view>
					<view class="textCen mar-top20" style="color: #868686;">暂无数据</view>
				</view>
				<block v-for="(item,index) in list" :key="index">
					<view class="wid90 mar mar-top40 borRad20 bacFFF" style="padding: 25rpx 0;box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);">
						<view class="wid90 mar dis disAl disJuB">
							<view class="dis disAl" style="height: 100rpx;">
								<image :src="item.coverimg" class="hei100 borRad50 mar-right20" style="width: 100rpx;"></image>
								<view class="fowe800 foSi40">{{item.name}}</view>
							</view>
							<view class="dis disAl disJuC borRad10 coFFF foSi20" :style="'background-color: '+theme.main_color+';'"
								style="width: 120rpx;height: 46rpx;" @click="confirm_replace(index)">更换</view>
						</view>
					</view>
				</block>
				<view style="height: 50rpx;"></view>
			</scroll-view>
		</view>
		<view v-if="xuan == 1" class="poFix wid100 dis disAl disJuC bacFFF" style="height: 124rpx;bottom: 0;">
			<view class="wid90 borRad40 dis disAl disJuC coFFF foSi35 hei86"
			 :style="'background-color: '+theme.main_color+';'">确定</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: this.global.url,
				xuan: 0,
				timer: null,
				sousuo: '',
				last_page: 0,
				page: 1,
				list: [],
				name: '',
				phone: '',
				remark: '',
				agencyList: [],
				agencyIndex: null,
				theme: null,
				orderid:'',
				confirm_tips:false
				
			}
		},
		onLoad(option) {
			this.orderid = option.orderid
			this.theme = uni.getStorageSync('theme')
			this.getList()
		},
		methods: {
			confirm_replace(index){
				let that = this
				let row = that.list[index]
				
				if(!that.confirm_tips && row.agent_id == 0){
					uni.showModal({
						title: '提示',
						// 提示文字
						content: '转出技师无所属代理商，转出后该订单管理将移交后台操作',
						// 取消按钮的文字自定义
						cancelText: "取消",
						// 确认按钮的文字自定义
						confirmText: "确认转单",
						//删除字体的颜色
						confirmColor: 'red',
						//取消字体的颜色
						cancelColor: '#000000',
						success: function(res) {
							if (res.confirm) {
								// 执行确认后的操作
								that.confirm_tips = true
								that.confirm_replace(index)
							} else {
								// 执行取消后的操作
							}
						}
					})
					return false
				}
				
				
				
				
				uni.showLoading({
					title:'加载中...'
				})
				uni.request({
					url: that.global.url + 'api/qianyu_smfw/agent/confirm_replace',
					method: "POST",
					header: {
						'site-id': that.global.site_id, //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						orderid:that.orderid,
						tech_id:row.id
					},
					success(res) {
						that.confirm_tips = false
						let result = res.data
						console.log(result.data)
						if (result.code == 1) {
							uni.showToast({
								title: result.msg,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'success',
								//显示持续时间为 2秒
								duration: 2000
							})
							setTimeout(()=>{
								uni.navigateBack()
							},1000)
						} else {
							uni.showToast({
								title: result.msg,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'error',
								//显示持续时间为 2秒
								duration: 2000
							})
						}
					},complete() {
						uni.hideLoading()
					}
				})
			},
			agencyChange: function(e) {
				if(this.agencyList.length > 0){
					this.agencyIndex = e.detail.value
				}
			},
			xuanClick(index){
				if(this.xuan != index){
					this.xuan = index
				}
			},
			sousuoInput: function(event) {
				var that = this
				if (that.timer !== null) clearTimeout(that.timer)
				that.timer = setTimeout(() => {
					that.sousuo = event.target.value
					console.log(that.sousuo)
					that.page = 1
					that.list = []
					that.getList()
				}, 1000)
			},
			lower(e) {
				if(this.last_page > this.page){
					this.page++
					this.getList()
				}
			},
			getList(){
				console.log('咋的了，执行啊')
				let that = this
				uni.showLoading({
					title:'加载中...'
				})
				uni.request({
					url: that.global.url + 'api/qianyu_smfw/agent/reject_tech',
					method: "POST",
					header: {
						'site-id': that.global.site_id, //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						city:uni.getStorageSync('city').id,
						orderid:that.orderid,
						keyword:that.sousuo,
						page:that.page,
						agent_id:uni.getStorageSync('agent_id')
					},
					success(res) {
						let result = res.data
						console.log(result.data)
						if (result.code == 1) {
							that.last_page = result.data.last_page
							that.list = that.list.concat(result.data.data)
						} else {
							uni.showToast({
								title: result.msg,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'error',
								//显示持续时间为 2秒
								duration: 2000
							})
						}
					},complete() {
						uni.hideLoading()
					}
				})
			},
			tiaozhuan(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	.content {
		min-height: 100vh;
	}
	.xia{
		height: 1rpx;
		background-color: #E5E5E5;
	}
	.butt1{
		width: 120rpx;
		height: 40rpx;
		color: #414040;
		border: 1rpx solid #414141;
		border-radius: 8rpx;
	}
	.butt2{
		width: 120rpx;
		height: 40rpx;
		background-color: #00AD27;
		border: 1rpx solid #00AD27;
		border-radius: 8rpx;
	}
</style>